package demo.practice.leetcode;

public class P1038 {

    //https://leetcode-cn.com/tag/binary-search-tree/
    public static void main(String[] args) {

        P1038 o= new P1038();
        TreeNode r= new TreeNode(3);
        r.left= new TreeNode(1);
        r.right= new TreeNode(4);
        r.left.right= new TreeNode(2);


        TreeNode froot = o.bstToGst(r);


    }


    Integer totall=0;

    public TreeNode bstToGst(TreeNode root) {
        if (root == null) {
            return root;
        }
        if (root.right != null) {
            bstToGst(root.right);
        }
        totall += root.val;
        root.val = totall;

        if (root.left != null) {
            bstToGst(root.left);
        }
        return root;
    }


//    TreeNode totallNode;
//    Integer totall;
/*
    public void bstToGst(TreeNode root,Boolean isRight) {

        if(root==null)
            return;

        if(root.right!=null){
            bstToGst( root.right,true);
        }

        if(isRight){

        }

        return null;
    }*/
}
